<template>
    <h2>信息录入</h2>
    <table>
        <tr>
            <th>姓名</th>
            <th>
                <input type="text" v-model="data.name">
            </th>
        </tr>
        <tr>
            <th>手机号</th>
            <th>
                <input type="text" v-model="data.phone">
            </th>
        </tr>
        <tr>
            <th>邮箱</th>
            <th>
                <input type="text" v-model="data.email">
            </th>
        </tr>
        <tr>
            <th>地址</th>
            <th>
                <input type="text" v-model="data.adder">
            </th>
        </tr>
        <tr>
            <th>爱好</th>
            <th>
                <input type="text" v-model="data.aihao">
            </th>
        </tr>
        <tr>
            <th>习惯</th>
            <th>
                <input type="text" v-model="data.xiguan">
            </th>
        </tr>
        <tr>
            <th>年龄</th>
            <th>
                <input type="text" v-model="data.age">
            </th>
        </tr>
        <tr>
            <th>身份证号</th>
            <th>
                <input type="text" v-model="data.sfz">
            </th>
        </tr>
        <tr>
            <th></th>
            <th>
                <input type="button" value="注册" @click="audd">
            </th>
        </tr>
    </table>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
const router=useRouter();

const data=ref({
    "mid": 0,
  "name": "",
  "phone": "",
  "email": "",
  "adder": "",
  "aihao": "",
  "xiguan": "",
  "age": "",
  "sfz": ""
})

const audd=()=>{


    var sst=/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
    if(!sst.test(data.value.phone))
{
    alert('手机号格式不正确');
    return;
}

    if(data.value.name=="")
{
    alert('用户名不为空');
    return;
}

var aat=/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
if(!aat.test(data.value.email))
{

    alert('邮箱格式不正确');
    return;
}

    axios.post("https://localhost:7253/api/VS/Add",data.value).then(res=>{
        if(res.data>0)
    {
        alert('注册成功');
    }
    else
    {
        alert('注册失败');
        return;
    }
    })
}
</script>

<style scoped>

</style>